<template>
  <view>
    <my-search @myClick="myClick" :bgColor="'#f36414'"></my-search>
    <view class="scroll-view-container">
      <scroll-view class="left-scroll-container" scroll-y :style="{height:useWidth + 'px'}">
        <view :class="['left-scroll-item', active === i ? 'active':'']" v-for="(item,i) in cateList" :key="i" @click="clickActive(i)">{{item.cat_name}}</view>
      </scroll-view>
      <scroll-view class="right-scroll-container" scroll-y :style="{height:useWidth + 'px'}" :scroll-top="scrollTop">
        <view class="cate-lv2" v-for="(item, i) in subCateList" :key="i">
          <view class="right-title"> / {{item.cat_name}} /</view>
          <view class="cate-lv3">
            <view class="right-body" v-for="(item1, i ) in item.children" :key="i" @click="gotoGoodList(item1)">
               <image :src="item1.cat_icon.replace('ugo-dev','hmugo-web')" mode="widthFix"></image>
               <text>{{item1.cat_name}}</text>
            </view>     
          </view>
        </view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
    mixins:[badgeMix],
		data() {
			return {
				// 视口可用宽度
        useWitdh: 0,
        // 分类数据列表
        cateList: [],
        // 激活标识
        active:0,
        // 二级数据
        subCateList:[],
        scrollTop:0
        
			};
		},
    onLoad() {
      // 设备信息
      const phoneInfo = uni.getSystemInfoSync()
      // console.log(phoneInfo)
      this.useWitdh = phoneInfo.windowHeight
      this.getCateList()
    },
    methods:{
      async getCateList() {
        const {data: res} = await uni.$http.get('/api/public/v1/categories')
        if(res.meta.status !== 200) return uni.$showMsg()
        this.cateList = res.message
        this.subCateList = res.message[0].children
      },
      clickActive(i) {
        this.active = i,
        this.subCateList = this.cateList[i].children,
        this.scrollTop = this.scrollTop ? 0 : 1
      },
      gotoGoodList(item1) {
        uni.navigateTo({
          url:'/subpackge/goods_lists/goods_lists?cid=' + item1.cat_id
        })
      },
      myClick() {
        console.log('~~~~')
      }
    }
	}
</script>

<style lang="scss">
.scroll-view-container {
  display: flex;

  .left-scroll-container {
    width: 120px;

    .left-scroll-item {
      line-height: 60px;
      background-color: #f7f7f7;
      text-align: center;
      font-size: 12px;

      // 激活项的样式
      &.active {
        background-color: #ffffff;
        position: relative;

        // 渲染激活项左侧的红色指示边线
        &::before {
          content: ' ';
          display: block;
          width: 3px;
          height: 30px;
          background-color: #f36414;
          position: absolute;
          left: 0;
          top: 50%;
          transform: translateY(-50%);
        }
      }
    }
  }
}
.right-title {
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  padding: 15px 0;
}
.cate-lv3 {
  display: flex;
  flex-wrap: wrap;

  .right-body {
    width: 33.33%;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;

    image {
      width: 60px;
      height: 60px;
    }

    text {
      font-size: 12px;
    }
  }
}



</style>
